/**
 * Copyright © Copyright Kevin Doyle 2012 Rhebogue Road,Limerick, Ireland.
 * Contact me at kfrdoyle@gmail.com This software was created by me Kevin Doyle
 * in 07/03/2012. I made is available to the public on 07/03/2012. You need my
 * permission to use this software in a commercial context. Although this code
 * is hosted on google code I do not agree with the licensing policy of google
 * code.
 */
package project_core;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.media.*;
import javax.swing.Timer;

/**
 *
 * @author Kevin Doyle
 */
public class SimGUI extends javax.swing.JFrame implements ActionListener {

    int a = 300;
    //  private ExocetMissileWayPoint flightPoints = new MBDAMissileWayPointFactory().CreateExocetWayPoint("ExocetAM39WayPoint");
    //  MBDANavigator ExocetNavigator;
    //  ExocetMissile ExocetAM39 = new MBDAMissileFactory().CreateExocet("ExocetAM39");
    int exocetLaunchFlag = 0; //use this to check all lat/lon/alt have been set before launch
    Timer guiUpdateTimer;//timer for checking for guiupdates
    Timer exocetRadarBlipTimer;//timer for checking for all over system messages
    Timer radarBlipTimer;
    Timer exocetTelemetry;
    // private String jTextPaneText = "";
    SoundEventPlayer sep1 = new SoundEventPlayer();
    SoundEventPlayer sep2 = new SoundEventPlayer();
    SoundEventPlayer sep3 = new SoundEventPlayer();
    SimDataLogic simdatalogic;

    /**
     * Creates new form SimGUI
     */
    public SimGUI() {

        initComponents();

        //  jTASystemMessages.append("Exocet: READY");
        // jTASystemMessages.append("\nGoal Keeper: READY");
        guiUpdateTimer = new Timer(450, this);//polling jCB's for change event
        guiUpdateTimer.setActionCommand("updateGUI");
        guiUpdateTimer.start();
        exocetRadarBlipTimer = new Timer(3000, this);//output output messages 
        exocetRadarBlipTimer.setActionCommand("exocetRadarBlip");
        radarBlipTimer = new Timer(2500, this);//output output messages 
        radarBlipTimer.setActionCommand("CIWSRADAR");
        radarBlipTimer.start();
        exocetTelemetry = new Timer(1000, this);
        exocetTelemetry.setActionCommand("TELEMETRY");
        simdatalogic = new SimDataLogic();//start this logic control unit

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPBaseLayer = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel9 = new RadarScreen();
        jPanel6 = new javax.swing.JPanel();
        jCBLaunchLatitude = new javax.swing.JComboBox();
        jCBLaunchLongitude = new javax.swing.JComboBox();
        jCBLaunchAltitude = new javax.swing.JComboBox();
        jTFExocetStatus = new javax.swing.JTextField();
        jCBTargetLatitude = new javax.swing.JComboBox();
        jCBTargetLongitude = new javax.swing.JComboBox();
        jBLaunchExocetMethod = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLLatitude = new javax.swing.JLabel();
        jLLongitude = new javax.swing.JLabel();
        jLAltitude = new javax.swing.JLabel();
        jLRange = new javax.swing.JLabel();
        jLFwdAzimuth = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTASystemMessages = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Thales Versus MBDA");
        setBackground(new java.awt.Color(0, 0, 0));
        setBounds(new java.awt.Rectangle(0, 0, 1100, 560));
        setIconImages(null);
        setMaximizedBounds(new java.awt.Rectangle(0, 0, 1100, 560));
        setMinimumSize(new java.awt.Dimension(1100, 560));

        jPBaseLayer.setBackground(new java.awt.Color(0, 153, 204));
        jPBaseLayer.setMaximumSize(new java.awt.Dimension(1100, 550));
        jPBaseLayer.setMinimumSize(new java.awt.Dimension(1100, 550));
        jPBaseLayer.setPreferredSize(new java.awt.Dimension(1100, 550));

        jPanel3.setBackground(new java.awt.Color(153, 204, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thales Goal Keeper CIWS", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP, new java.awt.Font("Arial", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel3.setMaximumSize(new java.awt.Dimension(350, 528));
        jPanel3.setMinimumSize(new java.awt.Dimension(350, 528));
        jPanel3.setPreferredSize(new java.awt.Dimension(350, 528));

        jScrollPane1.setHorizontalScrollBar(null);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/goalkeeper.png"))); // NOI18N

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPane2.setHorizontalScrollBar(null);
        jScrollPane2.setPreferredSize(new java.awt.Dimension(350, 824));

        jTextPane1.setBorder(null);
        jTextPane1.setContentType("text/html");
        jTextPane1.setEditable(false);
        jTextPane1.setText("<html>\r\n  <head>\r\n\r\n  </head>\r\n  <body>\r\n<table size=\"340\" border=\"0\"><tr><td>\n    <p style=\"margin-top: 0\">\r<font face=\"verdana\" size=\"3\" color=\"blue\">\n    <b>  \rTHALES Goal Keeper RADAR History</b><br><br>\nGoalkeeper is a Dutch close-in weapon system (CIWS) introduced in 1979 and in use as of 2011, \nwhich primarily defends ships against incoming missiles and ballistic shells. <br><br>\nThis system consists of an auto-cannon and advanced radar which in typically six seconds detects incoming fire, determines its trajectory, \nand aims and fires the gun.<br> <br>The system is fully automatic, needing no human input once activated.\n</font>\n    </p></td></tr></table>\r\n  </body>\r\n</html>\r\n");
        jScrollPane2.setViewportView(jTextPane1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel1)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(11, 11, 11)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane1.setViewportView(jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(153, 204, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "MBDA Exocet Anti Ship Missile", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP, new java.awt.Font("Arial", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel5.setMaximumSize(new java.awt.Dimension(350, 32767));
        jPanel5.setMinimumSize(new java.awt.Dimension(350, 0));
        jPanel5.setPreferredSize(new java.awt.Dimension(350, 341));

        jScrollPane3.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setMaximumSize(new java.awt.Dimension(305, 32767));
        jPanel4.setMinimumSize(new java.awt.Dimension(305, 100));
        jPanel4.setPreferredSize(new java.awt.Dimension(305, 472));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/exocet.png"))); // NOI18N

        jTextPane2.setContentType("text/html");
        jTextPane2.setEditable(false);
        jTextPane2.setText("<html>\r\n  <head>\r\n\r\n  </head>\r\n  <body>\r<table size=\"340\" border=\"0\"><tr><td>\n    <p style=\"margin-top: 0\">\n<font face=\"verdana\" size=\"3\" color=\"blue\">\n      \r<b>EXOCET Missile History</b><br><br>\nThe Exocet is a French-built anti-ship missile whose various versions can be launched from surface vessels, submarines, helicopters and fixed wing aircraft.\n<br><br> The missile's name is the French word for flying fish from the Latin name exocoetus. \n<br><br>The Exocet is built by MBDA, a European missile company. \n<br><br>The Exocet AM.39 is the air-launched version.\n\n</font>\n    </p></td></tr></table>\n  </body>\r\n</html>\r\n");
        jScrollPane4.setViewportView(jTextPane2);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(29, 29, 29)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane3.setViewportView(jPanel4);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel1.setBackground(new java.awt.Color(153, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "RADAR Tracking", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP, new java.awt.Font("Arial", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N

        jPanel9.setBackground(new java.awt.Color(0, 0, 0));
        jPanel9.setMaximumSize(new java.awt.Dimension(255, 255));
        jPanel9.setMinimumSize(new java.awt.Dimension(255, 255));
        jPanel9.setPreferredSize(new java.awt.Dimension(255, 255));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(52, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel6.setBackground(new java.awt.Color(153, 204, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Exocet Launcher", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP, new java.awt.Font("Arial", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel6.setPreferredSize(new java.awt.Dimension(282, 100));

        jCBLaunchLatitude.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jCBLaunchLatitude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBLaunchLatitudeActionPerformed(evt);
            }
        });

        jCBLaunchLongitude.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jCBLaunchLongitude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBLaunchLongitudeActionPerformed(evt);
            }
        });

        jCBLaunchAltitude.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jCBLaunchAltitude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBLaunchAltitudeActionPerformed(evt);
            }
        });

        jTFExocetStatus.setBackground(new java.awt.Color(51, 51, 51));
        jTFExocetStatus.setEditable(false);
        jTFExocetStatus.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTFExocetStatus.setForeground(new java.awt.Color(204, 0, 0));
        jTFExocetStatus.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTFExocetStatus.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jCBTargetLatitude.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jCBTargetLatitude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBTargetLatitudeActionPerformed(evt);
            }
        });

        jCBTargetLongitude.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jCBTargetLongitude.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCBTargetLongitudeActionPerformed(evt);
            }
        });

        jBLaunchExocetMethod.setText("Launch Exocet");
        jBLaunchExocetMethod.setEnabled(false);
        jBLaunchExocetMethod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLaunchExocetMethodActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/exocetMM40.png"))); // NOI18N

        jLabel4.setForeground(new java.awt.Color(102, 102, 102));
        jLabel4.setText("© Kevin Doyle kfrdoyle@gmail.com");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBLaunchExocetMethod)
                    .addComponent(jLabel3)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jCBTargetLatitude, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jCBLaunchAltitude, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jCBLaunchLatitude, 0, 132, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCBTargetLongitude, 0, 149, Short.MAX_VALUE)
                            .addComponent(jTFExocetStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                            .addComponent(jCBLaunchLongitude, javax.swing.GroupLayout.Alignment.LEADING, 0, 149, Short.MAX_VALUE)))
                    .addComponent(jLabel4))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCBLaunchLatitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBLaunchLongitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCBLaunchAltitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTFExocetStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCBTargetLatitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCBTargetLongitude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBLaunchExocetMethod)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBackground(new java.awt.Color(153, 204, 255));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Telemetry", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BELOW_TOP, new java.awt.Font("Arial", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N

        jPanel8.setBackground(new java.awt.Color(153, 204, 255));

        jLabel5.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(0, 0, 204));
        jLabel5.setText("Latitude:");

        jLabel6.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(0, 0, 204));
        jLabel6.setText("Longitude:");

        jLabel7.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(0, 0, 204));
        jLabel7.setText("Altitude:");

        jLabel8.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(0, 0, 204));
        jLabel8.setText("Range:");

        jLabel9.setFont(new java.awt.Font("Verdana", 1, 10)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(0, 0, 204));
        jLabel9.setText("Fwd Azimuth:");

        jLLatitude.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLLatitude.setForeground(new java.awt.Color(255, 51, 0));
        jLLatitude.setText("[0]");

        jLLongitude.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLLongitude.setForeground(new java.awt.Color(255, 51, 0));
        jLLongitude.setText("[0]");

        jLAltitude.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLAltitude.setForeground(new java.awt.Color(255, 51, 0));
        jLAltitude.setText("[0]");

        jLRange.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLRange.setForeground(new java.awt.Color(255, 51, 0));
        jLRange.setText("[0]");

        jLFwdAzimuth.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLFwdAzimuth.setForeground(new java.awt.Color(255, 51, 0));
        jLFwdAzimuth.setText("[0]");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLLatitude)
                    .addComponent(jLLongitude)
                    .addComponent(jLAltitude)
                    .addComponent(jLRange)
                    .addComponent(jLFwdAzimuth))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLLatitude)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLLongitude)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLAltitude)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jLRange, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLFwdAzimuth)))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTASystemMessages.setBackground(new java.awt.Color(51, 51, 51));
        jTASystemMessages.setColumns(20);
        jTASystemMessages.setEditable(false);
        jTASystemMessages.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jTASystemMessages.setForeground(new java.awt.Color(204, 0, 0));
        jTASystemMessages.setRows(5);
        jScrollPane5.setViewportView(jTASystemMessages);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane5)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPBaseLayerLayout = new javax.swing.GroupLayout(jPBaseLayer);
        jPBaseLayer.setLayout(jPBaseLayerLayout);
        jPBaseLayerLayout.setHorizontalGroup(
            jPBaseLayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPBaseLayerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPBaseLayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPBaseLayerLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPBaseLayerLayout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPBaseLayerLayout.setVerticalGroup(
            jPBaseLayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPBaseLayerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPBaseLayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPBaseLayerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, 0, 230, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPBaseLayer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPBaseLayer, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBLaunchExocetMethodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLaunchExocetMethodActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {

                sep1.setLaunchSound(1);//play the launch sound
                exocetRadarBlipTimer.start();//start emitting events to trigger radar sounds
                sep3.setLaunchSound(2);//start repeated play of exocet radar blip
                guiUpdateTimer.stop();//stop polling the jCB's for state change
                jBLaunchExocetMethod.setEnabled(false);//after launch disable launch button

                jTFExocetStatus.setText("SYSTEM ACTIVE");//update system status
                //     ExocetNavigator = new MBDANavigator(ExocetAM39);//start the navigation system
                //  jTFExocetStatus.setText(ExocetAM39.getSystemStatuses(1));
                exocetTelemetry.start();
                //   printFlight();
            }
        });


    }//GEN-LAST:event_jBLaunchExocetMethodActionPerformed
    /*
     * private void printFlight() {
     *
     *
     * Iterator<ExocetMissileWayPoint> itr =
     * ExocetAM39.flightdata.descendingIterator(); StringBuilder sb = new
     * StringBuilder(); int line = 1; String
     * header="\n[Latitude]\t\t[Longitude]\t\t[Altitude]\t[Range]\n";
     * jTASystemMessages.append(header); while (itr.hasNext() ) {
     *
     * flightPoints = itr.next(); line++;
     *
     *
     * jTASystemMessages.append(Double.toString(flightPoints.getLatitude())+
     * "\t"+Double.toString(flightPoints.getLongitude())+
     * "\t"+Double.toString(flightPoints.getAltitude())+
     * "\t"+Double.toString(flightPoints.getDecreasingRangeToTarget())+"\n");
     *
     * }
     * jTASystemMessages.append(header); }
     *
     */
    private void jCBLaunchLatitudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBLaunchLatitudeActionPerformed
        exocetLaunchFlag++;
        //  ExocetAM39.setLaunchlat((Double) jCBLaunchLatitude.getSelectedItem());
    }//GEN-LAST:event_jCBLaunchLatitudeActionPerformed

    private void jCBLaunchLongitudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBLaunchLongitudeActionPerformed
        exocetLaunchFlag++;
        //  ExocetAM39.setLaunchlon((Double) jCBLaunchLongitude.getSelectedItem());
    }//GEN-LAST:event_jCBLaunchLongitudeActionPerformed

    private void jCBLaunchAltitudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBLaunchAltitudeActionPerformed
        exocetLaunchFlag++;
        // ExocetAM39.setLaunchAlt((Double) jCBLaunchAltitude.getSelectedItem());
    }//GEN-LAST:event_jCBLaunchAltitudeActionPerformed

    private void jCBTargetLatitudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBTargetLatitudeActionPerformed
        exocetLaunchFlag++;
        //  ExocetAM39.setTargetLat((Double) jCBTargetLatitude.getSelectedItem());
    }//GEN-LAST:event_jCBTargetLatitudeActionPerformed

    private void jCBTargetLongitudeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCBTargetLongitudeActionPerformed
        exocetLaunchFlag++;
        // ExocetAM39.setTargetLon((Double) jCBTargetLongitude.getSelectedItem());
    }//GEN-LAST:event_jCBTargetLongitudeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String... args) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SimGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SimGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SimGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SimGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new SimGUI().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBLaunchExocetMethod;
    private javax.swing.JComboBox jCBLaunchAltitude;
    private javax.swing.JComboBox jCBLaunchLatitude;
    private javax.swing.JComboBox jCBLaunchLongitude;
    private javax.swing.JComboBox jCBTargetLatitude;
    private javax.swing.JComboBox jCBTargetLongitude;
    private javax.swing.JLabel jLAltitude;
    private javax.swing.JLabel jLFwdAzimuth;
    private javax.swing.JLabel jLLatitude;
    private javax.swing.JLabel jLLongitude;
    private javax.swing.JLabel jLRange;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPBaseLayer;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTASystemMessages;
    private javax.swing.JTextField jTFExocetStatus;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equalsIgnoreCase("updateGUI")) {
            if (exocetLaunchFlag == 5) {
                jBLaunchExocetMethod.setEnabled(true);
            }
        } else if (e.getActionCommand().equalsIgnoreCase("CIWSRADAR")) {
            sep2.setLaunchSound(4);//play the 1 sec repeated radar alt sound
        } else if (e.getActionCommand().equalsIgnoreCase("TELEMETRY")) {
            jLLatitude.setText(Double.toString(a += 28));
            jLLongitude.setText(Double.toString(a += 39));
            jLAltitude.setText(Double.toString(a += 14));
            jLRange.setText(Double.toString(a += 75));
            jLFwdAzimuth.setText(Double.toString(a += 45));
        }
    }
}

class RadarScreen extends javax.swing.JPanel implements ActionListener {

    private BufferedImage bufferedRadarBeam = null;
    private BufferedImage bufferedRadarHousing = null;
    double x = 0, y = 360;
    Timer radarTimer;//private final int animateDelay = 2050;

    public RadarScreen() {
        try {
            bufferedRadarBeam = ImageIO.read(new File("src/resources/radarBeam.png"));
            bufferedRadarHousing = ImageIO.read(new File("src/resources/radarhousing.png"));
        } catch (IOException e) {
            Logger.getLogger(RadarScreen.class.getName()).log(Level.SEVERE, null, e);
        }
        // try {
        //  bufferedRadarHousing = ImageIO.read(new File("resources/radarhousing.png"));
        //  } //catch (IOException e) {
        //     Logger.getLogger(RadarScreen.class.getName()).log(Level.SEVERE, null, e);
        // }
        radarTimer = new Timer(100, this);
        radarTimer.start();

    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);// call superclass's paintComponent

        //Create 2D by casting g to graphics2D
        Graphics2D g2d = (Graphics2D) g;


        //Control the quality of the graphics versus performance
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

        g2d.setRenderingHints(rh);
        g2d.setStroke(new BasicStroke(1));
        g2d.setColor(Color.green);
        g2d.drawImage(bufferedRadarHousing, 0, 0, null);
        //draw radar outter boundry circle
        g2d.draw(new Arc2D.Double(1, 1, 250, 250, 0, 360, 0));
        //draw radar half way mark
        g2d.draw(new Arc2D.Double(66, 66, 125, 125, 0, 360, 0));
        //draw quadrant lines
        g2d.draw(new Line2D.Double(125, 0, 125, 250));
        g2d.draw(new Line2D.Double(0, 125, 250, 125));
        g2d.draw(new Line2D.Double(50 + (x / 4), 50 + (x / 4), 50 + (x / 4), 50 + (x / 4)));
        g2d.draw(new Line2D.Double(210, 210 - x / 4, 211, 211 - x / 4));


        // Save the original transform associated with the current graphics contexts.
        AffineTransform saveTransform = g2d.getTransform();


        // Create a default identity affine transform, and apply to the current Graphics2D context
        AffineTransform identity = new AffineTransform();
        g2d.setTransform(identity);
        //Move origin to 200,200
        g2d.translate(126, 126);

        //Rotate the RADAR Beam 360°
        g2d.rotate(x);
        g2d.drawImage(bufferedRadarBeam, 0, 0, null);



        // Restore original transform before completing
        g2d.setTransform(saveTransform);
        g2d.translate(200, 200);


        //support unix systems
        Toolkit.getDefaultToolkit().sync();
        //put g out for GC
        g2d.dispose();
        g.dispose();

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //counters for continous radar rotation 
        if (x < y) {
            x += .2;


        }
        if (x > y - 20) {
            x = 0;
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                repaint();//repaint every time a drawing change occurs to create the 
                //effect of animation
            }
        });
    }
}

class SoundEventPlayer implements ControllerListener, java.util.EventListener {

    Player mediaPlayer;
    private File soundFile;
    private final File launchSoundFile = new File("src/resources/heavyLaunch.wav");
    private final File gunDishSoundFile = new File("src/resources/gundish.wav");
    private final File radarLockSoundFile = new File("src/resources/growlock.wav");
    private final File radarMSQ50SoundFile = new File("src/resources/MSQ50.wav");
    int choice;

    public SoundEventPlayer() {
    }//end constructor

    private void playRepeatedAudio(File soundFile) {
        String turl = "file:" + soundFile;//make string look like a url
        URL mediaURL = null;
        try {
            mediaURL = new URL(turl);
        } catch (MalformedURLException ex) {
            Logger.getLogger(SoundEventPlayer.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            // create a player without a gui to play the media specified in the URL
            mediaPlayer = Manager.createPlayer(mediaURL);
            mediaPlayer.addControllerListener(this);
            mediaPlayer.start();
        } catch (NoPlayerException noPlayerException) {
            System.err.println("No media player found");
        } catch (IOException iOException) {
            System.err.println("Error reading from the source");
        }

    }

    private void playAudio(File soundFile) {
        String turl = "file:" + soundFile;//make string look like a url
        URL mediaURL = null;
        try {
            mediaURL = new URL(turl);
        } catch (MalformedURLException ex) {
            Logger.getLogger(SoundEventPlayer.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            // create a player without a gui to play the media specified in the URL
            mediaPlayer = Manager.createPlayer(mediaURL);
            mediaPlayer.start();
        } catch (NoPlayerException noPlayerException) {
            System.err.println("No media player found");
        } catch (IOException iOException) {
            System.err.println("Error reading from the source");
        }

    }

    @Override
    public void controllerUpdate(ControllerEvent ce) {

        // the EndOfMediaEvent indicates we've run out of data
        if (ce instanceof EndOfMediaEvent) {
            // rewind (i.e. set media time to 0
            mediaPlayer.setMediaTime(new Time(0));
            try {
                Thread.sleep(3000);
            } catch (InterruptedException ex) {
                Logger.getLogger(SoundEventPlayer.class.getName()).log(Level.SEVERE, null, ex);
            }
            mediaPlayer.start();
        }


    }

    public void setLaunchSound(int choice) {
        this.choice = choice;//pass in value to object
        switch (choice) {
            case 1:
                if (!launchSoundFile.exists()) {
                    System.err.println("Wave file not found: " + soundFile.getPath().toString());
                } else {
                    soundFile = launchSoundFile;
                    playAudio(soundFile);
                }
                break;
            case 2:
                if (!gunDishSoundFile.exists()) {
                    System.err.println("Wave file not found: " + soundFile.getPath().toString());
                } else {
                    soundFile = gunDishSoundFile;
                    playRepeatedAudio(soundFile);
                }
                break;
            case 3:
                if (!radarLockSoundFile.exists()) {
                    System.err.println("Wave file not found: " + soundFile.getPath().toString());
                } else {
                    soundFile = radarLockSoundFile;
                    playAudio(soundFile);
                }
                break;
            case 4:
                if (!radarMSQ50SoundFile.exists()) {
                    System.err.println("Wave file not found: " + soundFile.getPath().toString());
                } else {
                    soundFile = radarMSQ50SoundFile;
                    playAudio(soundFile);
                }
                break;
            default:
                break;
        }//end switch    
    }
}